#include "stdafx.h"
#include "StoneGame.h"

HandType PK( HandType eLeft,HandType eRight )
{
    if (eLeft == HT_NULL || eRight == HT_NULL)
    {
        return HT_NULL;
    }

    if (eLeft == eRight)
    {
        return HT_NULL;
    }

    SPair akPair[] = {
        {HT_STONE,HT_CLIPPER},
        {HT_CLIPPER,HT_CLOTH},
        {HT_CLOTH,HT_STONE}};

        for (int i = 0;i < _countof(akPair);i++)
        {
            if (eLeft == akPair[i].eLeft)
            {
                return eRight == akPair[i].eRight ? eLeft : eRight;
            }
        }

        return HT_NULL;
}

std::map<HandType,std::vector<int>> CalResult( const std::vector<HandType>& raiHands )
{
    std::map<HandType,std::vector<int>> kResult;

    for (int i = 0;i < raiHands.size();i++)
    {
        kResult[raiHands[i]].push_back(i);
    }

    if (kResult.size() == 1 || kResult.size() == 3)
    {
        kResult.clear();
        return kResult;
    }

    if (kResult.size() == 2)
    {
        std::map<HandType,std::vector<int>>::iterator kIter = kResult.begin();
        std::map<HandType,std::vector<int>>::iterator kIter1 = kIter;
        std::map<HandType,std::vector<int>>::iterator kIter2 = ++kIter;

        HandType eType = PK(kIter1->first,kIter2->first);
        if (eType == HT_NULL)
        {
            assert(0);
            kResult.clear();

            return kResult;
        }
        std::vector<int> aiIndex = kResult[eType];
        kResult.clear();

        kResult[eType] = aiIndex;
        return kResult;
    }

    assert(0);
    kResult.clear();

    return kResult;
}

